package com.linjm.manageweb.controller;

import com.linjm.bean.SkuInfo;
import com.linjm.bean.SkuLsInfo;
import com.linjm.service.ListService;
import com.linjm.service.SpuService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

@RestController
@CrossOrigin
public class EsController {
    @DubboReference
    private ListService listService;
    @DubboReference
    private SpuService spuService;

    @RequestMapping("onSale")
    public  String onSale(String skuId) throws IOException {
        SkuLsInfo skuLsInfo = new SkuLsInfo();
        SkuInfo skuInfo = spuService.getSkuInfo(skuId);
        //属性拷贝
        BeanUtils.copyProperties(skuInfo, skuLsInfo);
        listService.saveSkuInfo(skuLsInfo);
        return skuLsInfo.toString();
    }
}
